
export default {
  name: 'reportList',
  functional: true,
  render(h, ctx) {
    const record = ctx.props.record;
    const events = ctx.props.events ?? false;
    const index = ctx.props.index;
    const reportHandler = ctx.props.reportHandler;

    const currentLeg = events ? record : record.flightLegs?.find(item => record.totalLeg - item.leg === 0) ?? record.flightLegs?.[0] ?? {};
    // 只有有out无in才能上传报文
    // const muFlag = currentLeg.outTime && !currentLeg.inTime;
    return [
      <span>
        { currentLeg.efReport
          ? <a-dropdown >
            <div slot='overlay' class='report-list-item-btn-main'>
              EF - 当前故障
            </div>
            <a href='javascript:;' class='mr-8' onClick={(e) => reportHandler(e, currentLeg, 'efReportVisible', index)}>EF</a>
          </a-dropdown> : ''}
        { currentLeg.isFault
          ? <a-dropdown >
            <div slot='overlay' class='report-list-item-btn-main'>
           FS - 故障汇总
            </div>
            <a href='javascript:;' class='mr-8' onClick={(e) => reportHandler(e, currentLeg, 'faultReportVisible', index)}>FS</a>
          </a-dropdown> : ''}
        { currentLeg.isSnapshot
          ? <a-dropdown >
            <div slot='overlay' class='report-list-item-btn-main'>
              S - 维护数据快照
            </div>
            <a href='javascript:;' class='mr-8' onClick={(e) => reportHandler(e, currentLeg, 'snapshotVisible', index)}>S</a>
          </a-dropdown> : ''}
        { currentLeg.isResearch
          ? <a-dropdown >
            <div slot='overlay' class='report-list-item-btn-main'>
              R - 故障研究
            </div>
            <a href='javascript:;' onClick={(e) => reportHandler(e, currentLeg, 'taskResearchVisible', index)}>R</a>
          </a-dropdown> : ''}
      </span>,
      <a-dropdown placement='bottomRight' overlay={() => {
        return (
          <a-menu >
            <a-menu-item disabled={!currentLeg.efReport}>
              { currentLeg.efReport
                ? <a href='javascript:;'
                  onClick={(e) => reportHandler(e, currentLeg, 'efReportVisible', index)}>EF - 当前故障</a> : 'EF - 当前故障'}
            </a-menu-item>
            <a-menu-item disabled={!currentLeg.isFault}>
              { currentLeg.isFault
                ? <a href='javascript:;'
                  onClick={(e) => reportHandler(e, currentLeg, 'faultReportVisible', index)}>FS - 故障汇总</a> : 'FS - 故障汇总'}
            </a-menu-item>
            <a-menu-item disabled={!currentLeg.isSnapshot}>
              { currentLeg.isSnapshot
                ? <a href='javascript:;'
                  onClick={(e) => reportHandler(e, currentLeg, 'snapshotVisible', index)}>S - 事件快照</a> : 'S - 事件快照'}
            </a-menu-item>
            <a-menu-item disabled={!currentLeg.isResearch}>
              {currentLeg.isResearch
                ? <a href='javascript:;'
                  onClick={(e) => reportHandler(e, currentLeg, 'taskResearchVisible', index)}>R - 故障研究</a> : 'R - 故障研究'}

            </a-menu-item>
            <a-menu-item>
              <a href='javascript:;'
                onClick={(e) => reportHandler(e, currentLeg, 'flightLegHistoryVisible', index) }>历史航段</a>
            </a-menu-item>
            <a-menu-item>
              <a href='javascript:;'
                onClick={(e) => reportHandler(e, currentLeg, 'flightLegDetailsVisible', index)}>航段详情</a>
            </a-menu-item>

            <a-menu-item >
              <a href='javascript:;'
                onClick={(e) => reportHandler(e, { ...currentLeg, eta: record.eta ?? '', phase: record.phase ?? '' }, 'messageUploadVisible', index)}>报文上传</a>
            </a-menu-item>
          </a-menu>
        );
      }}>
        <a-icon component={require('@/assets/icon/More_vertical.svg')} class='export-more'/>
      </a-dropdown>
    ];
  }
};
//       // 判断该航段是否包含当前时间而亮起
//       let rangeClass = '';
//       if (
//         new Date() >= new Date(flightLeg.outTime) &&
//         new Date() <= new Date(et) &&
//         !flightLeg.etopsFlight
//       ) {
//         rangeClass = 'in-time';
//       } else if (flightLeg.etopsFlight) {
//         rangeClass = 'or-time';
//       }

//       // 当前航段event点
//       const eventArr = [];
//       const eventArrO = [];

//       const wArr = [];
//       for (let ei = 0; ei < events.length; ei++) {
//         const element = events[ei];
//         const eItemL = moment.utc(element.msgTime).diff(moment.utc(flightLeg.outTime), 'minute');
//         const eItemL = moment.utc(element.msgTime).diff(moment.utc(flightLeg.outTime), 'minute');
//         const eItemDate = eItemL / ((e + es) - (s + ss)) * 100;
//         wArr.push(eItemDate);
//       }
//       wArr.sort((a, b) => a - b);

